#pragma once

#include"cs/msg_descriptor.h"

namespace cftc::reflect
{
    class Object;
}

namespace cftf::net
{
    class TcpListener;
}

class GGSession;
class GGListener : public cftf::util::Singleton<GGListener>
{
    friend class cftf::util::Singleton<GGListener>;
    GGListener();
 public:
    void Init();
    void UnInit();

    template<typename T>
    void SendMsg(int socket_handle, std::shared_ptr<T> msg)
    {
        static auto msgid = cs::MsgDescriptor::FindMsgId((T*)nullptr);
        InternalSendMsg(socket_handle, msgid, msg);
    }

    bool TouchSession(int socket_handle, std::function<void(GGSession*)> cb);

private:

    void InternalSendMsg(int socket_handle, unsigned short msgid, std::shared_ptr<cftc::reflect::Object> msg);

private:
    std::shared_ptr<cftf::net::TcpListener> tcplistener_;
};
